package com.hengpeng.itfin.service.impl;

import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.hengpeng.common.config.ConfigManager;
import com.hengpeng.common.config.expander.PropertiesExpander;
import com.hengpeng.itfin.service.PageConfigLoad;
import com.hengpeng.itfin.service.PersistService;
import com.hengpeng.itfinbase.persist.PageConfig;

public class PageConfigLoadImpl implements PageConfigLoad
{
	public static final Log log = LogFactory.getLog(PageConfigLoadImpl.class);

	@Autowired
	public PersistService persistService;

	private Set<String> loadKey;

	@Override
	public void init()
	{
		if (loadKey != null)
		{
			for (String key : loadKey)
			{
				loadProperties(key);
			}
		}
	}

	public PropertiesExpander loadProperties(String key)
	{
		PageConfig pageConfig = persistService.get(PageConfig.class, key);
		if (pageConfig != null)
		{
			ConfigManager.setPropertiesConfig(pageConfig.getId(), pageConfig.getValue());
		}
		return ConfigManager.getPropertiesConfig(pageConfig.getId());

	}

	public Set<String> getLoadKey()
	{
		return loadKey;
	}

	public void setLoadKey(Set<String> loadKey)
	{
		this.loadKey = loadKey;
	}
}
